<template>
	<view>
		<div>
			<navitop> 
				<i class="iconfont icon-jiantou-copy" slot="left-slot" @click="outlot"></i>
				<span slot="center-slot">添加</span>
				<!-- <i class="iconfont icon-youcecaidan" slot="right-slot"  @click="tapPopup(data)"></i> -->
			</navitop>
		</div>
		
		<div class="detial" :style='window_height'>
			<div style="background-color: #f0f0f0;" class="public_mag_top"></div>
			<scroll-view class="staff_b" scroll-y="true" touch-action=none; >
				<div class="public_list_out">
					<div class="public_list">
						<div class="public_list_left_one">
							<text style="color:red">*</text><text>活动名称:</text>
						</div>
						<div class="public_list_right">
							<input type="text"  v-model="dataSorce.activityTitle" >
						</div>
					</div>
					<div class="public_list">
						<div class="public_list_left_one">
							<text style="color:red">*</text><text>活动类型:</text>
						</div>
						<div class="public_list_right">
							<input type="text"  v-model="dataSorce.activityType" @click="class_actv" disabled='true'>
						</div>
					</div>
					<div class="public_list">
						<div class="public_list_left_one">
							<text style="color:red">*</text><text>活动状态:</text>
						</div>
						<div class="public_list_right">
							<input type="text"  v-model="dataSorce.activityState" @click="statu()" disabled='true'>
						</div>
					</div>
					<div class="public_list">
						<div class="public_list_left_one">
							<text style="color:red">*</text><text>负责人:</text>
						</div>
						<div class="public_list_right">
							<input type="text"  v-model="dataSorce.activityOwnerName" @click="name_click()" disabled='true'>
						</div>	
					</div>
					<div class="public_list">
						<div class="public_list_left_one">
							<text>预期收益(元):</text>
						</div>
						<div class="public_list_right">
							<input type="text"  v-model="dataSorce.anticipatedRevenue" >
						</div>
					</div>
					<div class="public_list">
						<div class="public_list_left_one">
							<text>实际成本(元):</text>
						</div>
						<div class="public_list_right">
							<input type="text"  v-model="dataSorce.actualCost" >
						</div>
					</div>
					<div class="public_list">
						<div class="public_list_left_one">
							<text>预算成本(元):</text>
						</div>
						<div class="public_list_right">
							<input type="text"  v-model="dataSorce.budgetCost" >
						</div>
					</div>
					<div class="public_list">
						<div class="public_list_left_one">
							<text>期望成功率(%):</text>
						</div>
						<div class="public_list_right">
							<input type="text"  v-model="dataSorce.expectedSuccessRate" >
						</div>
					</div>
					<div class="public_list" @click="altime(1)">
						<div class="public_list_left_one">
							<text>开始时间:</text>
						</div>
						<div class="public_list_right">
							<span style="width: 75%;">
								<kxTime :date='dataSorce.startTime' @rundata='kxdatetime' :default_time="1"></kxTime>
							</span>
						</div>
					</div>
					<div class="public_list" @click="altime(2)">
						<div class="public_list_left_one">
							<text>结束时间:</text>
						</div>
						<div class="public_list_right">
							<span style="width: 75%;">
								<kxTime :date='dataSorce.endTime' @rundata='kxdatetime' :default_time="0"></kxTime>
							</span>
						</div>
					</div>
				</div><br><br>
				<div :style="heigsdiv"></div>
				<div class="public_button" :style="heigs">
					<div class="public_text" @click="okclick">
						保&nbsp;&nbsp;存
					</div>
				</div>
			</scroll-view>
		</div>
		<!-- 弹窗组件 -->
		<popus ref="alert">
			<alertcenter @row="row" :titles="titles" :rundata="rundata" :dataSorc="datas" ></alertcenter>
		</popus>
		
		<chunLeiPopups v-model="value" :popData="data" @tapPopup="tapPopup" :x="345" :y="95" placement="top-end"></chunLeiPopups>
		
	</view>
</template>

<script>
	import navitop from '@/components/common/navi-top'
	import chunLeiPopups from "@/components/chunLei-popups/chunLei-popups"
	import alertcenter from '@/pages/common/common/alert/alertgx'
	import kxTime from "@/components/kx-datetime/kx-datetime"	
	import popus from '@/uni_modules/uni-popup/components/uni-popup/uni-popup'
	import {acdetail,activitysave,namelist,dataList,batchDelete} from '@/common/api/job/jobapi.js'
	export default {
		components:{
			navitop,
			alertcenter,
			chunLeiPopups,
			popus,
			kxTime
		},
		props:{
			selid: {
				default: ''
			}
		},
		data(){
			return {
				window_height:'',
				dataSorce: [],
				rundata: [],
				datas: [],
				data: [	{title:"商机",code:2,icon: 'icon-bianji'},
				{title:"删除",code:3,icon: 'icon-shanchu'}],
				date: '', //需要展示的时间数据
				value:false,
				titles: '商机列表',
				heigs:'',
				heigsdiv: 0,
				status: [{name:'计划中',code:'activityState'},{name:'执行中',code:'activityState'},{name: '终止',code:'activityState'},{name: '完成',code:'activityState'}],
				time_code: '',	// 获取选中时间code
				actv_class: [],	// 特色	
				user_name: [],	// 负责人
				
			}
		},
		mounted() {
			uni.onKeyboardHeightChange(res => {
				res.height = res.height + 50;
				this.heigsdiv = 'height:' + res.height  + 'px;' ;
				this.heigs = 'height:' + res.height + 'px;' ;
			})
		   const res = uni.getSystemInfoSync();
		   this.window_height = 'height:' + res.windowHeight + 'px;';
			  
			  // 获取下拉列表
			namelist({source: 'activity'}).then((rows) =>{
				if(rows.code == 200){
					this.actv_class = rows.data[0].val.split(',')
				}
			})
			
			// 获取员工列表
			dataList({isLoadUser: 2}).then((rows) => {
				if(rows.code == 200){
					console.log(rows.data)
					for(let i in rows.data){
						if(rows.data[i].id.split('_')[1] == "user"){
							this.user_name.push(rows.data[i]);
						}
					}
				}
			})
			
			// 初始化数据
			this.dataSorce = {
				activityOwnerId:'',
				activityOwnerName: '',
				activityState: '',
				activityTitle: '',
				activityType: '',
				actualCost:'',
				anticipatedRevenue: '',
				budgetCost: '',
				endTime:'',
				expectedSuccessRate: '',
				startTime: ''
			}
	
			
			
			
		},
		methods:{
			
			// 关闭窗口
			outlot(){
				this.$emit('closeslist',2)
			},
			
			// 状态
			statu(){
				this.titles = '活动状态'
				this.datas = this.status;
				this.$refs.alert.open('bottom');
			},
			
			// 类型
			class_actv(){
				let rusn = [];
				for(let i in this.actv_class){
					rusn.push({name:this.actv_class[i],code:'activityType'})
				}
				this.titles = '活动类型'
				this.datas = rusn;
				this.$refs.alert.open('bottom');
			},
			
			// 负责人
			name_click(){
				this.titles = '负责人'
				this.user_name.forEach(item => {
					this.$set(item,'code','activityOwnerName')
				})
				this.datas = this.user_name;
				this.$refs.alert.open('bottom');
			},
			
			// 获取时间code
			altime(val){
				this.time_code = val;
			},
			
			// 获取时间
			kxdatetime(e){
				if(this.time_code == 1){
					this.dataSorce.startTime = e.substr(0,10);
				}
				if(this.time_code == 2){
					this.dataSorce.endTime = e.substr(0,10);
				}
				console.log(this.dataSorce)
			},
			
			
			//  获取弹窗返回结果
			row(val){
				if(val.code == 'activityOwnerName'){
					this.dataSorce.activityOwnerId = val.id.split('_')[0]
				}
				this.dataSorce[val.code] = val.name;
				this.$refs.alert.close();
			},
			
			// 保存
			 okclick(){
				 if(!this.dataSorce.activityOwnerName){
					 uni.showToast({
					 	title: '请输入负责人',
						icon: 'error'
					 })
					 return false;
				 }
				 if(!this.dataSorce.activityTitle){
					 uni.showToast({
						title: '请输入活动类型',
						icon: 'error'
					 })
					  return false;
				 }
				 if(!this.dataSorce.activityTitle){
					 uni.showToast({
						title: '请输入活动名称',
						icon: 'error'
					 })
					  return false;
				 }
				 
				 if(!this.dataSorce.activityState){
					 uni.showToast({
						title: '请输入活动状态',
						icon: 'error'
					 })
					  return false;
				 }
				 activitysave(this.dataSorce).then((rows)=> {
					 if(rows.code == 200){
						 uni.showToast({
						 	title: '保存成功'
						 })
						 setTimeout(()=>{
							this.$emit('closeslist',1)
						 },1500)
					 }else{
						 uni.showToast({
						 	title: reslut.message,
							icon: 'error'
						 })
					 }
				 })
			 }
		}
	}
	
</script>

<style scoped lang="scss">
.detial {
	height: 100%;
	padding-top: 95rpx;
	width: 100%;
	background-color: #fff;
	.detial_text{
		div {
			width: 95%;
			display: flex;
			// justify-content: space-between;
			margin: auto;
			height: 90rpx;
			line-height: 89rpx;
			border-bottom: 1px solid #f0f0f0;
		}
		
	}
	.detial_text text{
		// width: 40%;
		text-align: left;
		padding-right: 10rpx;
		padding-left: 30rpx;
		color: #808080;
	}
	.detial_text span{
		// padding-left: 30rpx;
	}
	.detial_text input{
		// height: 90rpx;
		width: 60%;
		border: 1px solid #cacaca;
		border-radius: 4px;
	}
	
	input:hover {
			border: 1px solid #1890ff;
	}	
}
.stats {
	width: 200px;
	height: 100rpx;
	z-index: 1;
}
.title {
	margin-top: 1px;
	height: 90rpx;
	background-color: #fff;
	line-height: 90rpx;
	padding-left: 10px;
	border-bottom: 1px solid #f0f0f0;
	border-radius: 4px;
}
.second_list {
	height: 90rpx;
	margin-top: 1px;
	background-color: #fff;
	line-height: 90rpx;
	padding-left: 20px;
	border-radius: 4px;

}
</style>
